﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Core.Repository.BasicSet;
using WaterRevenueMS.Componnent.Entities.BasicSet;
using WaterRevenueMS.Componnent.Common;
using WaterRevenueMS.Domain.ViewModels.BasicSet.WayOfCharge;

namespace WaterRevenueMS.Core.Service.BasicSet.Impl
{
    [Export(typeof(IWayOfChargeService))]
    public class WayOfChargeService : CoreServiceBase, IWayOfChargeService
    {
        [Import]
        public IWayOfChargeRepository WayOfChargeRepository { get; set; }

        public IQueryable<WayOfCharge> WayOfCharges
        {
            get { return WayOfChargeRepository.Entities; }
        }

        public OperationResult Insert(WayOfChargeModel model)
        {
            var entity = new WayOfCharge
            {
                Shou_FFS=model.Shou_FFS,
                DefaultValue=model.DefaultValue,
                CreateDT=DateTime.Now,
                ReviseDT=DateTime.Now,
                OrderNo=model.OrderNo,
                Shou_FLX=model.Shou_FLX,
                Shou_FYF=model.Shou_FYF,
                Shou_FRQ=model.Shou_FRQ
            };
            WayOfChargeRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Update(WayOfChargeModel model)
        {
            var entity = WayOfChargeRepository.Entities.FirstOrDefault(t => t.Id == model.Id);
            if (entity != null)
            {
                entity.Shou_FFS = model.Shou_FFS;
                entity.DefaultValue = model.DefaultValue;
                entity.ReviseDT = DateTime.Now;
                entity.OrderNo = model.OrderNo;
                entity.Shou_FLX = model.Shou_FLX;
                entity.Shou_FYF = model.Shou_FYF;
                entity.Shou_FRQ = model.Shou_FRQ;
                WayOfChargeRepository.Update(entity);
            }
            return new OperationResult(OperationResultType.Success, "更新成功");
        }

        public OperationResult Delete(int Id)
        {
            var entity = WayOfChargeRepository.Entities.FirstOrDefault(t => t.Id == Id);
            if (entity != null)
            {
                WayOfChargeRepository.Delete(entity);
            }
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
